package com.atguigu.gmall.publisher.controller;


import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.publisher.bean.DauInfo;
import com.atguigu.gmall.publisher.bean.DetailItemInfo;
import com.atguigu.gmall.publisher.bean.NameValue;
import com.atguigu.gmall.publisher.service.OrderRealtimeService;
import com.atguigu.gmall.publisher.service.VisitRealtimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PublisherController {

    @Autowired
    VisitRealtimeService visitRealtimeService;

    @Autowired
    OrderRealtimeService orderRealtimeService;


    @GetMapping("/dauRealtime")
    public  String dauRealtime(@RequestParam("td") String td){
        System.out.println("查询日活信息："+td);
        DauInfo dauInfo= visitRealtimeService.getDauInfo(td);
        return JSON.toJSONString(dauInfo);
    }

    @GetMapping("/statsByItem")
    public String  statsByItem(@RequestParam("itemName") String  itemName,
                               @RequestParam("date") String date,
                               @RequestParam("t")String type){

       List<NameValue> nameValueList=  orderRealtimeService.statsByItem( itemName,   date, type);
       return  JSON.toJSONString(nameValueList);
    }

    @GetMapping("/detailByItem")
    public String detailByItem(@RequestParam("itemName") String  itemName,
                                @RequestParam("date") String date,
                                @RequestParam("pageNo")  Integer pageNo ,
                                @RequestParam("pageSize") Integer pageSize){

        DetailItemInfo detailItemInfo= orderRealtimeService.detailByItem(itemName,date ,pageNo ,pageSize);

        return  JSON.toJSONString(detailItemInfo);
    }


}
